﻿@using System.Text.RegularExpressions
@using ORM.Business.Models.Entities
@model ORM.Business.Models.Entities.GuideComment
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ckeditor/ckeditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ckeditor/adapters/jquery.js")"></script>
   @Html.TextAreaFor(item => item.ContentHtml, new { id = "guidecommentContent" })
    @Html.ValidationMessageFor(model => model.ContentHtml)
<br/>
<div style="text-align: right">
<input type="button" id="submitGuideComment" value="Đăng bình luận" style="height: 25px; width: 120px; font-size: 13px"/>
</div>
<br/><br/>
<script type="text/javascript">
    var guidecommentEditor =  CKEDITOR.replace('guidecommentContent',
    {
    filebrowserImageBrowseUrl: '/Scripts/ckfinder/ckfinder.html?type=Images',
    filebrowserImageUploadUrl: '/Scripts/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images',
    removePlugins : 'elementspath',
    toolbar: 'Custom', //makes all editors use this toolbar
   toolbarStartupExpanded : false,
   toolbarCanCollapse  : false,
   toolbar_Custom: ''
    });
    $(document).ready(function() {
          $("#submitGuideComment").click(function () {
            for (var instanceName in CKEDITOR.instances) {
            var string = CKEDITOR.instances[instanceName].getData();
            string = string.replace(/<\/?[^>]+(>|$)/g, "");
            string = string.replace(/[&]nbsp[;]/gi," ");
            if(string.trim() != "") {
                CKEDITOR.instances[instanceName].updateElement();
            }            
        }
            $('#guidecommentContent').attr("disable","disable");
            var content = $('#guidecommentContent').val();                  
                $.ajax ({
                    type: "POST",
                    url: "@Url.Action("SubmitGuideComment", "Guide")",
                    dataType: "text",
                    data: {  
                        GuideId: @Model.GuideId,
                        ContentHtml: content
                    },
                    success: function (data) {
                          guidecommentEditor.setData("");
                        ReloadCommentTab(2,@Model.GuideId);
                        var total = parseInt($("#guideComment").html());
                            $("#guideComment").html(total + 1);
        },
                    error: function (result,error) {
                        alert ( " Can't do because: " + error.responseText );                        
                    },

                    complete: function() {
                       $('#guidecommentContent').attr("disable","");
                    }
                });
        });
    });
</script>



